package com.visionblue.business.ship.base

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.Nullable
import androidx.fragment.app.Fragment
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.cancel

/**
 * @author: xlh
 * @date: 2020-04-10 1:46 PM
 * @desc:
 */
abstract class BaseFragment : Fragment(), CoroutineScope by MainScope() {

    abstract val layoutId: Int

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(layoutId, container, false)
    }

    override fun onActivityCreated(@Nullable savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        initView(savedInstanceState)
        initData()
    }

    protected abstract fun initView(savedInstanceState: Bundle?)

    protected open fun initData() {

    }

    override fun onDestroyView() {
        super.onDestroyView()
        cancel()
    }

}